import domain from 'ad-ui-domain'
import createReducer from 'ad-ui-reducer'
import { AppState, IStoreLoading } from '@stores/interface'

interface IAccount {
  id: string
  name: string
  verifyStatus: string
  type: string
  registerMail: string
  organizationId: string
  [propName: string]: any
}

export interface IUserInfo extends IStoreLoading {
  id: string
  account: IAccount
  authoriseList: string[]
  givenName: string
  loginName: string
  photo: string | null
  superAdmin: boolean
  superAdminName: string
  username: string
  [propName: string]: any
}

const Model = 'User'
const Config = {
  fetchMe: (enitity: AppState, response: IUserInfo) => domain.create(Model, response),
  logout: '$logout',
}

export default createReducer(Model, Config)
